//
//  ViewController.m
//  BlueToothProject
//
//  Created by Apple on 2016/12/6.
//  Copyright © 2016年 yxw. All rights reserved.
//

#import "ViewController.h"
#import "UIViewController+ImagePicker.h"
#import "BabyBluetooth.h"
#import "SVProgressHUD.h"
#import "SelectAlert.h"
#import "UIImage+Convert.h"
#import "NSData+String.h"
#import "NSString+Hex.h"

#import "BlueToothService.h"

#import "PhotoViewController.h"

#import "DiyDrawViewController.h"
#import "Module2ViewController.h"

#import "GeneralClass.h"
#define channelOnPeropheralView @"peripheralView"
#define BleDataLengthMax                20

#define WeakObj(o) autoreleasepool{} __weak typeof(o) o##Weak = o;

// 设备特征值 -- 可做修改
static NSString *const DeviceUUID  =  @"FFE1";

@interface ViewController (){
}

@property (weak, nonatomic) IBOutlet UILabel *promptLabel;
@property (weak, nonatomic) IBOutlet UIButton *connectButton;
@property (nonatomic, strong) UILabel *progressLabel;
@property (weak, nonatomic) IBOutlet UIButton *sendButton;
@property (strong,nonatomic) BlueToothService * btService;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.btService = [BlueToothService sharedDefaultManager];
    @WeakObj(self);
    self.btService.changLab = ^(NSString *name){
        selfWeak.promptLabel.text = name;
    };
}

// 蓝牙连接
- (IBAction)connectBlueTooth:(UIButton *)sender {
    [self.btService connectBlueTooth:sender];
}

// 发送内置图片
- (IBAction)sendPhoto:(UIButton *)sender {
//    
//    if (!self.btService.isConnectSuccess) {
//        [SVProgressHUD showInfoWithStatus:@"请先连接设备"];
//        return;
//    }
    
    [self showCanEdit:NO image:^(UIImage *image){

        [self.btService transferPhotoWithImage:image];
    }];
    
}

//打开相机相册
- (IBAction)takePhoto:(id)sender {
    if (!self.btService.isConnectSuccess) {
        [SVProgressHUD showInfoWithStatus:@"请先连接设备"];
        return;
    }
    
    PhotoViewController *photoVC = [PhotoViewController new];
    photoVC.sendBlock = ^(UIImage *image){
        [self.btService transferPhotoWithImage:image];
    };
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:photoVC];
    
    [self presentViewController:nav animated:YES completion:nil];
}

- (IBAction)DiyAction:(id)sender {
    DiyDrawViewController *diyVc = [[DiyDrawViewController alloc]init];
    [self.navigationController pushViewController:diyVc animated:YES];
}

- (IBAction)Module2:(id)sender {
    Module2ViewController * module2 = [[Module2ViewController alloc] initWithNibName:NSStringFromClass([Module2ViewController class]) bundle:nil];
    [self.navigationController pushViewController:module2 animated:true];
}


@end
